Skip to content

feat: recall log and repeated-mistake count (#120) - #124

Merged
gosha70 merged 5 commits into
mainfrom
feat/120-recall-log
Nov 13, 2026
Merged

gosha70 merged 5 commits into
mainfrom
feat/120-recall-log

Conversation

@gosha70

@gosha70 gosha70 commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Refs #120. The build of the approved spec (#122, specs/memkernel-0-10-recall-log/).

Commits

  • 100d034 spec amendment A1 (the owner's, 2026-11-11): a normal session start shows memories without calling recall, so each hook block that shows memories logs the ref_ids it injected. Corrects the draft's checked fact on the session-start path.
  • b8df8fb the build.
  • a2db2f1 hook records use the service's settings (the FR-011 lesson), with a test for a lifecycle built without settings.
  • ea6a802 review fixes, amendment A2:
    1. a record larger than recall_log_max_bytes keeps its first ref_ids, then query text, up to the limit, marked truncated;
    2. on_post_compact(session_id="") logs only when given a session id (the owner's choice; Claude Code's hooks do not call it);
    3. the count evaluates every logged filter, including session_id_filter and include_needs_review, and a miss's evidence counts MCP recalls and hook blocks separately;
    4. shown_without_repeat counts each session once;
    5. the log is POSIX-locked like the store locks, with one warning per process on Windows (the owner's choice);
    6. mypy --strict passes on the eval modules (CI runs mypy src/ only).
  • 607f3aa second and third review rounds:
    • records keep query_sha256 (hash of the full query), and the count pairs tool records with transcript calls by it, so a cut query still pairs;
    • an oversized record gives up query text first, then trailing ref_ids, by binary search (10,000 ids: 5.6 s before, 0.006 s now); ref_ids_truncated is written only when ids were dropped, and only that makes a miss unknown;
    • include_needs_review is not judged in a miss's evidence: whether the memory was flagged at recall time is not known (listed in the report's limits);
    • recall_log_max_bytes is at least 4,096 bytes (RECALL_LOG_MIN_BYTES), so a full MCP record (seven filters, a 2,000-character query, an id) always fits;
    • an ambiguous tool record is kept as a possible record of each candidate session; if it may have returned the memory, the outcome is unknown, not missed;
    • recall-log lines are type-checked; malformed ones are skipped and counted (malformed_log_records).

Changes

  • Settings (config.py, README table): MEMKERNEL_RECALL_LOG (off), MEMKERNEL_RECALL_LOG_MAX_BYTES (5 MB), MEMKERNEL_RECALL_LOG_MAX_FILES (10).
  • src/memkernel/recall_log.py: one JSON line per record under MEMKERNEL_STATE_DIR/recall-log/<project_id>/recall.jsonl (with query_sha256), created mode 0600, locked on POSIX, rotated before an append would pass the size limit (at least 4,096 bytes); an oversized record is cut to fit and marked; a failed write is logged once per process and never fails the recall; nothing when off or for an in-memory store.
  • Call sites: the MCP recall tool (query and filters) and the session-start and compact-recovery blocks (session id, the ref_ids shown); on_post_compact only when given a session id. recall's results, the MCP tools and the hook scripts are unchanged. The spool's file lock is now public (session_spool.locked) and shared.
  • eval/repeat-mistakes/count.py: applies Question: has a repeated mistake ever been counted on memkernel sessions, in the lifecycle evaluation or in real use? #112's rule (D5), pairs tool records with the transcript's own recall calls (D2), and reports each repeat as shown, missed, other store or unknown (D6), with evidence and limits; --json too. Refuses a store path that does not exist.
  • eval/repeat-mistakes/transcripts.py: a temporary Claude Code transcript reader, until Context rescue: fix the compaction hooks, then capture session knowledge before it is lost (0.5.1 → 0.6) #59 Phase 2.
  • README: "Counting repeated mistakes": how to run it, the rule, a note to check the report before sharing (it quotes matched error text from memories and command output, with memory and session ids), and what it cannot detect. CHANGELOG under [Unreleased].

Tests

  • tests/unit/test_recall_log.py (10): record fields, mode 0600, query cap, off and in-memory, rotation, one-file mode, a failed write logged once, session-start and compact-recovery records, resume logs nothing.
  • tests/e2e/test_recall_log_tool.py: two MCP recalls leave two tool records with the returned ref_ids and filters.
  • tests/unit/test_repeat_mistakes_count.py (6): a fixture with two stores and seven sessions covering every outcome, a recall after the failure, a two-span memory line, an ambiguous pairing and a note that mentions an error (not counted); signature rule; a filter that excludes the memory.

Checks

  • ruff and format clean; mypy src/ and mypy --strict on eval/repeat-mistakes/ clean; fast suite 1082 passed, coverage 94.6%.
  • The count also ran on this repo's real Claude Code transcripts.
  • Origin gate: aligned, high (after the third round). DeepSeek on 607f3aa's changes: two rounds, PASS; one valid warning fixed (only cut ids, not a cut query, make a miss unknown), the rest notes. DeepSeek on ea6a802's fixes: PASS, three warnings answered. Earlier DeepSeek review: PASS; one typo fixed, three warnings answered (an oversized single record can pass the size limit by one line; ref_id matching by text relies on UUIDs; the 5-second pairing is two-sided, as the spec says).

…call-log)

A normal session start shows memories without calling recall, so logging only recall calls would report them as missed. The owner chose (2026-11-11) that each hook block that shows memories writes one record listing the ref_ids it injected. Corrects the draft's checked fact on the session-start path. Refs #120.
MEMKERNEL_RECALL_LOG (off by default) makes each MCP recall, and each hook block that shows memories, append one JSON line under MEMKERNEL_STATE_DIR/recall-log/<project_id>/, mode 0600, rotated by MEMKERNEL_RECALL_LOG_MAX_BYTES and _MAX_FILES. eval/repeat-mistakes/count.py applies #112's rule to the stores, the recall logs and Claude Code transcripts (temporary reader until #59 Phase 2) and reports each repeat as shown, missed, other store or unknown. recall's results, the MCP tools and the hook scripts are unchanged. README section and settings rows; CHANGELOG. Refs #120.
A lifecycle built without settings falls back to defaults, so its own state_dir, project_id and recall_log can differ from the store's (the FR-011 lesson). Hook records now use self._service.settings; a test pins that a lifecycle built without settings writes to the service's log. Review of PR #124.
1. A record larger than recall_log_max_bytes keeps its first ref_ids, then query text, up to the limit and is marked truncated. 2. on_post_compact(session_id="") logs only when given a session id (the owner's choice); Claude Code's hooks do not call it. 3. The count evaluates every logged filter (session_id_filter and include_needs_review too) and separates MCP recalls from hook blocks in a miss's evidence. 4. shown_without_repeat counts each session once. 5. The log is POSIX-locked like the store locks, with one warning per process on Windows (session_spool.locking(); the owner's choice). 6. mypy --strict passes on the eval modules. Spec amendment A2, README, CHANGELOG. Refs #120.
Second round: records keep query_sha256, the hash of the full query, and the count pairs by it; an oversized record gives up query text first, then trailing ref_ids (binary search, no longer quadratic); a record whose ref_ids were cut is marked ref_ids_truncated and makes a miss unknown; include_needs_review is not judged, since whether a memory was flagged at recall time is not known. Third round: recall_log_max_bytes is at least 4,096 bytes, so a full MCP record always fits; ambiguous tool records are kept as possible records of their candidate sessions and make a miss they may explain unknown; recall-log lines are type-checked, malformed ones skipped and counted. Spec A2, README, CHANGELOG. Refs #120.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant